<?php

/**
 * This is the model class for table "tbl_banners".
 *
 * The followings are the available columns in table 'tbl_banners':
 * @property string $banner_id
 * @property string $banner_title_th
 * @property string $banner_title_en
 * @property string $banner_content_th
 * @property string $banner_content_en
 * @property string $banner_picture
 * @property string $banner_create_date
 * @property string $banner_start_date
 * @property string $banner_expire_date
 * @property string $banner_update_date
 * @property string $banner_status
 * @property string $banner_creator
 */
class TblBanners extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_banners';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('banner_title_th, banner_title_en, banner_content_th, banner_content_en, banner_picture, banner_update_date, banner_creator', 'required'),
			array('banner_title_th, banner_title_en, banner_content_th, banner_content_en', 'length', 'max'=>255),
			array('banner_picture', 'length', 'max'=>250),
			array('banner_status', 'length', 'max'=>8),
			array('banner_creator', 'length', 'max'=>10),
			array('banner_create_date, banner_start_date, banner_expire_date', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('banner_id, banner_title_th, banner_title_en, banner_content_th, banner_content_en, banner_picture, banner_create_date, banner_start_date, banner_expire_date, banner_update_date, banner_status, banner_creator', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'banner_id' => 'Banner',
			'banner_title_th' => 'Banner Title Th',
			'banner_title_en' => 'Banner Title En',
			'banner_content_th' => 'Banner Content Th',
			'banner_content_en' => 'Banner Content En',
			'banner_picture' => 'Banner Picture',
			'banner_create_date' => 'Banner Create Date',
			'banner_start_date' => 'Banner Start Date',
			'banner_expire_date' => 'Banner Expire Date',
			'banner_update_date' => 'Banner Update Date',
			'banner_status' => 'Banner Status',
			'banner_creator' => 'Banner Creator',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('banner_id',$this->banner_id,true);
		$criteria->compare('banner_title_th',$this->banner_title_th,true);
		$criteria->compare('banner_title_en',$this->banner_title_en,true);
		$criteria->compare('banner_content_th',$this->banner_content_th,true);
		$criteria->compare('banner_content_en',$this->banner_content_en,true);
		$criteria->compare('banner_picture',$this->banner_picture,true);
		$criteria->compare('banner_create_date',$this->banner_create_date,true);
		$criteria->compare('banner_start_date',$this->banner_start_date,true);
		$criteria->compare('banner_expire_date',$this->banner_expire_date,true);
		$criteria->compare('banner_update_date',$this->banner_update_date,true);
		$criteria->compare('banner_status',$this->banner_status,true);
		$criteria->compare('banner_creator',$this->banner_creator,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

  	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return TblBanners the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
